/**
 * Exam No: Y8467136
 */
package japrc2011test;

import static org.junit.Assert.*;
import japrc2011.Robot;
import japrc2011.RobotException;
import japrc2011.RobotSimulator;
import japrc2011.RobotSimulatorException;
import japrc2011.SimulatorInterface;

import org.junit.Before;
import org.junit.Test;

public class SimulationLevel1Test {
    
    private SimulatorInterface rs;
    //Robot r;
    
    @Before
    public void setUp() throws Exception
    {
        rs = new RobotSimulator();
    }
	
	/**
	 * check that all commands ignore irrelevant whitespace characters
	 */
	@Test
    public void testIgnoreWhitespaceCharacters() {  
		rs.addRobot(new Robot("r1"));
        rs.sendCommand("r1", "    TEST" );
        rs.sendCommand("r1", "M    0    1");
        assertEquals(2, rs.getRobotInfo("r1", "COMMAND_COUNT"));
    }
	
	
	/**
	 * If an invalid command is sent to the robot, the command count does not increase.
	 */
	@Test
    public void testCommandCountinInvalidCommand() {  
		try
		{
		rs.addRobot(new Robot("r1"));
        assertEquals(0, rs.getRobotInfo("r1", "COMMAND_COUNT"));
        
        rs.sendCommand("r1", "TEST");
        assertEquals(1, rs.getRobotInfo("r1", "COMMAND_COUNT"));
        
        rs.sendCommand("r1", "invalid");
        fail();
		}
		catch(RobotException exc)
		{
			
		}
		assertEquals(1, rs.getRobotInfo("r1", "COMMAND_COUNT"));
		
		rs.sendCommand("r1", "M 0 1");
        assertEquals(2, rs.getRobotInfo("r1", "COMMAND_COUNT"));
        
        rs.sendCommand("r1", "TEST");
        assertEquals(3, rs.getRobotInfo("r1", "COMMAND_COUNT"));
        
        try
        {
        	rs.sendCommand("r1", "invalid");
        	fail();
        }
        catch(RobotException exc)
        {
        	
        }
        assertEquals(3, rs.getRobotInfo("r1", "COMMAND_COUNT"));
    }	
	
	/**
	 * Test for trying to add two robots in the map with the same name
	 * It throws exception! duplicated robot! r1 already exists
	 */
	@Test
    public void testSameNameRobots() { 
		try 
		{
			rs.addRobot(new Robot("r1"));
			rs.addRobot(new Robot("r2"));
			rs.addRobot(new Robot("r1"));
            fail();
        } 
		catch (RobotSimulatorException e) 
        { 
			
        }
    }
	
}
